import React, { Component } from 'react'
import TwsLayout from './component/tws-layout'
import { connect } from 'react-redux'

import * as url from './constant/constant-url'
import HomeworkDetailPageBody from './component/homework-detail-page-body'
import TutorAssignmentPageBody from './component/tutor-assignment-page-body'
import {getLangFromLocalStorage} from './constant/lang-util'
import locales from './locales'

import {
  HashRouter as Router,
  Route
} from 'react-router-dom'
import { IntlProvider } from 'react-intl'
import { LocaleProvider } from 'antd'

class App extends Component {
  render () {
    const lang = this.props.lang || getLangFromLocalStorage()
    const langData = locales[lang]

    return (
      <IntlProvider locale={langData.intlLocale} messages={langData.intlMessage}>
        <LocaleProvider locale={langData.locale}>
          <Router >
            <TwsLayout lang={lang}>
              <Route exact path='/' component={HomeworkDetailPageBody} />
              <Route exact path={url.studentAssignmentPageBodyUrl} component={HomeworkDetailPageBody} />
              <Route exact path={url.tutorAssignmentPageBodyUrl} component={TutorAssignmentPageBody} />
              <Route exact path={url.tutorAssignmentPageBodyDividerUrl} component={TutorAssignmentPageBody} />
            </TwsLayout>
          </Router>
        </LocaleProvider>
      </IntlProvider>
    )
  }
}

const mapStateToProps = ({lang}) => ({lang})

export default connect(mapStateToProps)(App)
